package model;

/**
 * This class represents a user of an auction-service.
 * The user has a name and can be logged into the system.
 * Futhermore the user can have some notifications from the server.
 *
 * @version 1.0 vom 16.10.2012
 * @author Peter Tillian 1026312
 */

import java.util.List;
import java.util.ArrayList;
import java.util.Collections;

public class User {
	private String username;
	private boolean loggedIn = false;
	private int rejectedGroupBids;
	private List<String> notifications;

	public User(String username) {
		this.username = username;
		this.notifications = Collections
				.synchronizedList(new ArrayList<String>());
		this.rejectedGroupBids = 0;
	}

	public User(String username, boolean loggedIn) {
		this(username);
		this.loggedIn = loggedIn;
	}

	public String getUsername() {
		return this.username;
	}

	public synchronized List<String> getNotifications() {
		return this.notifications;
	}

	public boolean isLoggedIn() {
		return this.loggedIn;
	}

	public void login() {
		this.loggedIn = true;
	}

	public void logout() {
		this.loggedIn = false;
		ConfirmMonitor.getInstance().checkDeadlockAfterUserLogout();
	}

	public synchronized void addNotification(String notification) {
		this.notifications.add(notification);
		this.notifyAll();
	}

	public boolean isIdentic(User other) {
		return this.username.equals(other.username);
	}
	
	public void addRejectedGroupBid() {
		this.rejectedGroupBids++;
	}
	
	public int getRejectedGroupBids() {
		return this.rejectedGroupBids;
	}
	
	public void resetRejectedGroupBids() {
		this.rejectedGroupBids = 0;
	}
} // end of class User